package com.xiaoyu.merchant.ui.activity.wallet;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.xiaoyu.commonlib.network.CommonHttpResponser;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.utils.PreferencesUtil;
import com.xiaoyu.commonlib.utils.ToastUtil;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.network.NetworkManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WithdrawDepositActivity extends BaseActivityWithTitle {

    @BindView(R.id.withdraw_card_name)
    TextView mCardName;
    @BindView(R.id.withdraw_deposit_txt)
    TextView mBankCardTxt;
    @BindView(R.id.confirm_withdrawal_edit_text)
    EditText mNum;

    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("提现金额");
        LayoutInflater.from(this).inflate(R.layout.activity_withdraw_deposit, parent, true);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        String cardNum = getIntent().getStringExtra(WalletActivity.BANK_CARD_NUM);
        mCardName.setText(getIntent().getStringExtra(WalletActivity.BANK_CARD_NAME));
        mBankCardTxt.setText("尾号" + cardNum.substring(cardNum.length() - 4));

    }

    @OnClick(R.id.confirm_withdrawal)
    public void confirmWithdrawalClick() {
        if (TextUtils.isEmpty(mNum.getText().toString())) {
            ToastUtil.showToast(this, "请输入金额");
            return;
        }
        getWithDraw();
    }

    //提现
    private void getWithDraw() {
        NetworkManager.withDrawal(PreferencesUtil.getString(PreferencesUtil.TOKEN, ""), mNum.getText().toString(), PreferencesUtil.getString(PreferencesUtil.PAY_PWD, ""), new CommonHttpResponser() {
            @Override
            public void onSuccess(String result) {
                ToastUtil.showToast(WithdrawDepositActivity.this, "确认提现成功");
                finish();
            }

            @Override
            public void onFailed(String errorCode, String errorDiscription) {

            }
        });
    }
}
